﻿using LightCAD.Core;
using LightCAD.Core.Elements;
using LightCAD.Three;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using QdArch.ThreeUtils;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Xml.Resolvers;
using Shape = LightCAD.Three.Shape;

namespace QdArch
{
    public partial class SlabAction
    {
        public override BufferGeometry[] CreateGeometry3D(LcElement element, Matrix3d matrix)
        {
            var slab = element as QdSlab;

            var outPoints = slab.OutLine.Select(p => p.ToThree()).ToJsArr();
            var start = slab.OutLine[0].ToThree(slab.Bottom);
            var end = slab.OutLine[1].ToThree(slab.Bottom);
            var lineVec = new Vector3().subVectors(end, start);
            var xAxis = VectorUtil.XAxis;
            var yAxis = VectorUtil.YAxis;
            var zAxis = VectorUtil.ZAxis;
            var coodMat = new Matrix4();
            //coodMat.makeBasis(xAxis, yAxis, zAxis);

            var holes = new JsArr<Path>();
            foreach (var innerPoints in slab.Holes)
            {
                holes.add(new Path(innerPoints.Select(p => p.ToThree()).ToJsArr()));
            }
            var shape = new Shape(outPoints)
            {
                holes = holes
            };
            double thicknessHlf = slab.Thickness / 2;
            var geoData = GeoUtil.GetStretchGeometryData(shape, coodMat, slab.Thickness, 0);
            var geo = geoData.GetBufferGeometry();
            geo.computeVertexNormals();

            return new BufferGeometry[] { geo };
        }
    }
}